clear all
set more off, permanently

save  "...\PADDD_impact.dta"

***************************** prepare data ************************************

*** pixels reduced in size in 2012 
gen enacR_12_B3=1 if enacR_0912_B3==1 & year_PADDD==2012
replace enacR_12_B3=0 if enacR_0912_B3==0

*before their reduction
gen R12protected2000_B3=1 if Rprotected2000_B3==1 & year_PADDD==2012
replace R12protected2000_B3=0 if Rprotected2000_B3==0 

*** pixels reduced in size in 2010 
gen enacR_10_B3=1 if enacR_0912_B3==1 & year_PADDD==2010
replace enacR_10_B3=0 if enacR_0912_B3==0

*state 
merge m:m PADDD using  "C:\Users\dkeles\Documents\these\article2\important\desigPA.dta", gen(mergedesig)
gen desig=1 if Designation=="Federal"
replace desig=1 if Designation=="federal"
replace desig=2 if Designation=="State"
replace desig=2 if Designation=="state"
bysort ID1: fillmissing desig, with(any)
drop mergedesig

gen enacRS_10_B3=enacR_10_B3
replace enacRS_10_B3=. if (enacR_10_B3==1 & desig!=2)

*before their reduction
gen R10protected2000_B3=1 if Rprotected2000_B3==1 & year_PADDD==2010
replace R10protected2000_B3=0 if Rprotected2000_B3==0 

*** pixels reduced in size in 2009 
gen enacR_09_B3=1 if enacR_0912_B3==1 & year_PADDD==2009
replace enacR_09_B3=0 if enacR_0912_B3==0

*before their reduction
gen R09protected2000_B3=1 if Rprotected2000_B3==1 & year_PADDD==2009
replace R09protected2000_B3=0 if Rprotected2000_B3==0 

******************************* matching ***************************************

set seed 12345 
gen sortorder = runiform()
sort sortorder

*** 2009 roraima

xi: psmatch2 enacR_09_B3 i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008  if  treecover2000>30 & enacR_09_B3!=. & defo_p0912==.  & ID_state==23, outcome(defo_1015) caliper(0.5) ties ai(3) n(3)  common logit odds
foreach var in  _self_defo_1015 _nn  _n1   _id _defo_1015 _weight _support _treated _pscore {
gen roraima`var'=`var'
}
pstest i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 , t(enacR_09_B3) mweight(roraima_weight) support (roraima_support) both 

*** 2012 para
xi: psmatch2 enacR_12_B3 i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009 treecoverloss2010 treecoverloss2011 if  treecover2000>30 & enacR_12_B3!=. & defo_p0912==.  & ID_state==14 ,  outcome(defo_1315)  caliper(0.5) ties ai(1) n(1) norepl common logit odds
foreach var in  _self_defo_1315 _nn  _n1   _id _defo_1315 _weight _support _treated _pscore {
gen para`var'=`var'
}
pstest i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009 treecoverloss2010 treecoverloss2011 , t(enacR_12_B3) mweight(para_weight) support (para_support) both

*** 2010 rondonia

xi: psmatch2 enacRS_10_B3 i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009  if  treecover2000>30 & enacR_10_B3!=. & defo_p0912==.  & ID_state==22 ,   outcome(defo_1115) caliper(0.5) ties ai(1) n(1) norepl common logit odds
foreach var in  _self_defo_1115 _nn  _n1   _id _defo_1115 _weight _support _treated _pscore {
gen rondonia`var'=`var'
}
pstest i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108  treecoverloss2001 treecoverloss2002 treecoverloss2003 treecoverloss2004 treecoverloss2005 treecoverloss2006 treecoverloss2007 treecoverloss2008 treecoverloss2009 , t(enacR_10_B3) mweight(rondonia_weight) support (rondonia_support) both
drop    _id _defo_1115 _weight _support _treated _pscore
mhbounds defo_1115, gamma(1 (0.10) 5) treated(rondonia_treated) weight(rondonia_weight) support(rondonia_support) 

save "...\results_impact_BZ10.dta", replace

